package com.pwx.web.interceptor;

import com.pwx.common.Const;
import com.pwx.entity.User;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Copyright (C),2021-2022,亚瑟王
 * FileName: LoginInterceptor
 * Author: saber
 * Date:2022/10/7 17:39
 */
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        User user =(User) request.getSession().getAttribute(Const.IS_LOGIN);
        if (user==null){
            response.sendRedirect(request.getContextPath()+"/login.jsp");
            return false;
        }else {
            return true;
        }
    }
}
